package com.realworld.controller;

import com.realworld.common.R;
import com.realworld.mapper.ArticleMapper;
import com.realworld.model.pojo.Article;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;


@RestController
@RequestMapping("tags")
@Api(tags = "获取标签")
public class tagController {
    @Resource
    private ArticleMapper articleMapper;
    @GetMapping
    public R getTags(){
        HashSet<String> set = new HashSet<>();
        List<Article> tags = articleMapper.getTags();
        tags.forEach(s->{
            String[] split = s.getTag().split(",");
            for (int i = 0; i < split.length; i++) {
                set.add(split[i]);
            }
        });
        return R.ok(set);
    }
}
